package main

import (
	"fmt"
	"time"
)

func isCancelled(c chan bool) bool {
	select {
		case <-c:
			return true
		default:
			return false
	}
}

func main() {
	chCancel:=make(chan bool)

	for i:=0; i<5; i++ {
		go func(i int){
			for {
				if isCancelled(chCancel) {
					break
				}
			}
			fmt.Println(i, "canceled")
		}(i)
	}

	time.Sleep(time.Millisecond*50)
	//chCancel<-true
	close(chCancel)
	time.Sleep(time.Millisecond*500)
}
